package com.atguigu.auth.service.Impl;


import com.atguigu.auth.mapper.SysUserMapper;
import com.atguigu.auth.service.SysUserService;
import com.atguigu.common.jwt.JwtHelper;
import com.atguigu.model.system.SysUser;
import com.atguigu.security.config.LoginUserInfoHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2025-06-20
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
/*    @Autowired
    private SysDeptService sysDeptService;

    @Autowired
    private SysPostService sysPostService;*/

    @Override
    public void updateStatus(Long id, Integer status) {
        if(status != 1 && status != 0){
            throw new RuntimeException("状态值非法");
        }
        SysUser sysUser = this.getById(id);
        sysUser.setStatus(status);
        this.updateById(sysUser);
    }

    /**
     * 根据用户名查询
     * @param username
     * @return
     */
    @Override
    public SysUser getByUsername(String username) {
        System.out.println("username:"+username);
        LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
        sysUserLambdaQueryWrapper.eq(SysUser::getUsername,username);
        return this.baseMapper.selectOne(sysUserLambdaQueryWrapper);
    }



    @Override
    public Map<String, Object> getCurrentUser() {
        SysUser sysUser = this.baseMapper.selectById(LoginUserInfoHelper.getUserId());
        //SysDept sysDept = sysDeptService.getById(sysUser.getDeptId());
        //SysPost sysPost = sysPostService.getById(sysUser.getPostId());
        Map<String, Object> map = new HashMap<>();
        map.put("name", sysUser.getName());
        map.put("phone", sysUser.getPhone());
        //map.put("deptName", sysDept.getName());
        //map.put("postName", sysPost.getName());
        return map;
    }

}
